import { http } from "@/utils/http";

/** 查询条件（分页） */
export interface ReportListCommand extends BasePageQuery {
  title?: string;
  reportType?: string;
  terminalType?: string;
  discoveryDate?: string;
  infoSource?: string;
  deptName?: string;
  status?: string; // 修改为统一的状态字段
  discoverUserName?: string;
  discoveryPlace?: string;
  dutyDeptId: number,
  acceptDeptId: number,
  reportId: number,
}

/** 返回的单条记录类型 */
export interface ReportPageResponse {
  reportId: number;
  title: string;
  terminalType: string;
  infoSource: string;
  dutyDeptId?: number;
  discoverer?: number;
  discoveryDate?: string;
  discoveryPlace?: string;
  reportType?: string;
  status?: "0" | "1" | "2"; // 修改为统一的状态字段
  fileFlag?: number;
  feedback?: string;
  createTime?: string;
  deptName?: string;
  discoverUserName?: string;
  infoDescribe?: string; // 新增 infoDescribe 字段
  updaterBy?: string;
  dealDeptName?: string;
  inspectionCheckId?: number;
  acceptDeptId?: number;
  basis?: string;

}

/** 新增安全信息 */
export interface AddReportCommand {
  title?: string;
  terminalType?: string;
  infoSource?: string;
  dutyDeptId?: number;
  basis?: string;
  discoverer?: number;
  discoveryDate?: string;
  discoveryPlace?: string;
  hiddenPeopleFlag?: string;
  acceptDeptId?: number;
  reportType?: string;
  infoDescribe?: string;
  status?: string;
  contactPerson?: number;
  contactPhone?: string;
  sourceId?: number;
  sourceType?: string;
  fileFlag?: number;
  feedback?: string;
  creatorId?: number;
}

/** 修改命令继承新增命令，加主键ID */
export interface UpdateReportCommand extends AddReportCommand {
  reportId: number;
  updaterId?: number;
  reformRequirement?: string; // 整改要求
  actionDeadline?: string; // 制定措施期限
  correctiveDeadline?: string; // 整改完成期限
  dutyDeptId?: number; // 责任单位
  dealDeptId?: number; // 整改单位
  userId?: number;
}

/** 分页获取安全信息 */
export function getReportListApi(params: ReportListCommand) {
  return http.request<ResponseData<PageDTO<ReportPageResponse>>>(
    "get",
    "/safety/report/list",
    { params }
  );
}

/** 导出Excel */
export const exportReportExcelApi = (
  params: ReportListCommand,
  fileName: string
) => {
  return http.download("/safety/report/excel", fileName, { params });
};

/** 删除安全信息（支持批量） */
export const deleteReportApi = (data: Array<number>) => {
  return http.request<ResponseData<void>>("delete", "/safety/report", {
    params: {
      ids: data.toString()
    }
  });
};

/** 新增安全信息 */
export interface AddReportCommand {
  title?: string;
  terminalType?: string;
  infoSource?: string;
  dutyDeptId?: number;
  basis?: string;
  discoverer?: number;
  discoveryDate?: string;
  discoveryPlace?: string;
  hiddenPeopleFlag?: string;
  acceptDeptId?: number;
  reportType?: string;
  infoDescribe?: string; // base64 或 null
  closeStatus?: string;
  contactPerson?: number;
  contactPhone?: string;
  sourceId?: number;
  sourceType?: string;
  fileFlag?: number;
  feedback?: string;
  creatorId?: number;
}

/** 新增接口 */
export const addReportApi = (data: AddReportCommand) => {
  return http.request<ResponseData<void>>("post", "/safety/report", {
    data
  });
};

/** 修改命令继承新增命令，加主键ID */
export interface UpdateReportCommand extends AddReportCommand {
  reportId: number;
  updaterId?: number;
}

/** 修改接口 */
export const updateReportApi = (data: UpdateReportCommand) => {
  return http.request<ResponseData<void>>("put", "/safety/report", {
    data
  });
};


/**  提交问题接口  */
export const submitProblemApi = (data: UpdateReportCommand) => {
  return http.request<ResponseData<void>>("post", "/safety/report/submitQuestion", {
    data
  });
};

/** 查询详情 */
export const getReportDetailApi = (reportId: number) => {
  return http.request<ResponseData<ReportPageResponse>>(
    "get",
    `/safety/report/${reportId}`
  );
};
